<template>
	<view class="master">
		<gyd-navbar back-color="#fff" :title="title" :isBack="false"></gyd-navbar>

		<view class="content">
			<view class="swiper">
				<gyd-swiper :list="bannerList"></gyd-swiper>
			</view>

			<view class="tools-card">
				<view class="title">常用功能</view>
				<gyd-func-menu :menu_type="1" :col="4"></gyd-func-menu>
			</view>

			<view class="school" @click="pageRoute('/merchantPages/school/school?type=' + memberInfo.admin.type)"
				v-if="businessSchool">
				<image :src="businessSchool.logo" mode="aspectFill"></image>
			</view>
		</view>

		<!-- 底部导航栏 -->
		<gyd-tabbar :current="0"></gyd-tabbar>
	</view>
</template>

<script setup>
	import request from '@/utils/request';
	import cache from '@/utils/cache';
	import util from '@/utils/util';
	import {
		ref,
		reactive,
		toRefs,
		inject,
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onPullDownRefresh,
		onReachBottom,
	} from '@dcloudio/uni-app';

	const state = reactive({
		title: '师傅首页',
		themeColor: cache.get('themeColor'),
		imgHost: util.requestUrl(),
		memberInfo: {},
		bannerList: [],
		businessSchool: false,
	});

	//在页面所有元素加载完成后执行（只执行一次）
	onLoad((opt) => {
		console.log('onLoad');
		if (opt.hasOwnProperty('id')) {
			console.log('传递参数', opt.id);
		}
		initData();
	});

	//在页面由不可见变为可见时执行（只要页面显示都会执行）
	onShow(() => {
		console.log('onShow');
	})

	//在页面解析完成之后执行
	onReady(() => {
		console.log('onReady');
	})

	onPullDownRefresh(() => {
		console.log('下拉刷新');
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
	})

	onReachBottom(() => {
		console.log('触底加载更多');
	})

	function initData() {
		state.memberInfo = {};

		state.bannerList = [{
			id: 1,
			title: '',
			image: state.imgHost + '/uploads/202508/file8abfb845c2964d0e059e90cff521a3b64648.jpg',
			link: '#',
		}, {
			id: 2,
			title: '',
			image: state.imgHost + '/uploads/202508/file682ed776a9d247ca390d79dd8ad39f8d7758.jpg',
			link: '/userPages/login/login',
		}];

		state.businessSchool = {
			logo: state.imgHost + '/uploads/202508/file4cac47ae168c56634c9ee79c24fa92811638.jpg'
		};
	}

	function pageRoute(url) {
		uni.navigateTo({
			url
		});
	}

	function pageTabRoute(url) {
		uni.reLaunch({
			url
		});
	}

	const {
		title,
		themeColor,
		imgHost,
		memberInfo,
		bannerList,
		businessSchool,
	} = toRefs(state);
</script>

<style lang="scss">
	.master {
		.content {
			padding: 0 $m24;

			.swiper {
				margin: 30rpx 0 0 0;
				border-radius: $radius-16;
			}

			/* #ifdef APP-PLUS */
			.swiper {
				margin: 80rpx 0 0 0;
				border-radius: $radius-16;
			}

			/* #endif */

			.tools-card {
				margin: $m16 0;
				border-radius: $radius-16;
				background: #fff;

				.title {
					@include f-between($align: center);
					padding: $m24 $m24 0 $m24;
					font-size: $font-30;
					color: $main-color;
					font-weight: 700;
				}
			}

			.school {
				width: 100%;
				height: 240rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: $radius-16;
				}
			}
		}
	}
</style>